package com.lovo.project.servlet.petOwner;

import com.lovo.project.exception.OurException;
import com.lovo.project.model.PetOwnDO;
import com.lovo.project.service.PetOwnService;
import com.lovo.project.service.impl.PetOwnServiceImpl;
import com.lovo.project.vo.ResultVO;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "AddPetOwnerServlet",value = "/petOwner/addPetOwner")
public class AddPetOwnerServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        try {
            String phone = request.getParameter("phone");
            String nickName = request.getParameter("nickName");
            String realName = request.getParameter("realName");
            String vip = request.getParameter("vip");
            String imageUrl=request.getParameter("imageUrl");
            String site = request.getParameter("site");
            String area = request.getParameter("area");
            String grade = request.getParameter("grade");
            PetOwnDO po = new PetOwnDO();
            po.setPetOwnerHeadimg(imageUrl);
            po.setPetOwnerName(nickName);
            po.setPetOwnerRealname(realName);
            po.setPetOwnerPhone(phone);
            po.setPetOwnerAddress(site);
            po.setPetOwnerArea(area);
            po.setPetOwnerPoints(grade);
            po.setPetVipCard(vip);
            PetOwnService service = new PetOwnServiceImpl();
            service.insertPetOwn(po);
            response.getWriter().print(ResultVO.success().toJson());
        }catch (OurException o){
            response.getWriter().print(ResultVO.fail(o.getCodeEnum()));
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
